#ifndef ADAPTER_H
#define ADAPTER_H

#include <QObject>
#include "GameCommon.h"
#include <QSerialPort>

class Adapter : public QObject
{
    Q_OBJECT
public:
    explicit Adapter(QObject *parent = nullptr);
    ~Adapter();


    void init(const QString &portName);

signals:
    void braceletReady(quint32 player, QByteArray braceletSn);

    void selectionCommit(quint32 player, int selection);

    void competationCommit(quint32 player);

public slots:
    void readBraceletSn(quint32 playerMask);
    void reset();
    void startToCompete();



private slots:
    void readDeviceData();


private :
    void ingestByte(quint8 data);
    void parse();
    void sendPackage(quint8 * buf, quint64 length);
    quint32  mapPlayerMask(quint8 rawId);

private:
    QSerialPort   m_port;
    quint32    m_status;
    QByteArray  m_cache;
};

#endif // ADAPTER_H
